/******************************************************************************
 * FileName:    gwin_global_config.c
 * Desc:        参数配置
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

/*-------------------------- Includes ---------------------------------------*/
#include "gwin_global_config.h"
#include "gwin_main_task.h"


/*-------------------------- Macro Definitions ------------------------------*/
#define LOCAL_DEBUG_EN                      ( 0 )
#if LOCAL_DEBUG_EN
#define GWIN_DEBUG(...)                     USER_DEBUG(__VA_ARGS__)
#else
#define GWIN_DEBUG(...)
#endif


/*-------------------------- Type Declarations ------------------------------*/

/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
/**
 * @brief 设置时区
 */
void gwin_set_timezone(int32_t value)
{
//    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_TIME_ZONE, value);
}

/**
 * @brief 设置utc
 */
void gwin_set_utc_time(uint32_t value)
{
//    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_UTC_TIME, value);
}

/**
 * @brief 设置天气
 */
void gwin_set_weather(uint32_t value)
{
//    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_WEATHER, value);
}

/**
 * @brief 设置配网
 */
void gwin_set_network_provisioned(uint8_t value)
{
    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK, value);
}

/**
 * @brief 设置ble连接
 */
void gwin_set_ble_connect(uint8_t value)
{
    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_GATT, value);
}

/**
 * @brief 设置ota
 */
void gwin_set_ota_state(uint8_t value)
{
    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_OTA_STATE, value);
}

/**
 * @brief 设置配网超时时间
 */
void gwin_set_network_timeout(uint32_t value)
{
    GWIN_DEBUG("%d", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK_TIMEOUT, value);
}

/**
 * @brief 设置model pid
 */
void gwin_set_model_pid(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_MODEL_PID, value);
}

/**
 * @brief 设置spec
 */
void gwin_set_spec_security(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_SPEC_SECURITY, value);
}

/**
 * @brief 设置spec
 */
void gwin_set_spec(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_SPEC, value);
}

/**
 * @brief 设置spec 保存
 */
void gwin_set_spec_save(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_set(MAIN_TASK_MSG_CFG_SUBTYPE_SPEC_SAVE, value);
}


/**
 * @brief 配置m_config的io变量的OOB属性 是否有OOB_USE_QR_CODE_OUT属性
 * @param enable_qr_code_out true:有OOB_USE_QR_CODE_OUT属性 false:没有OOB_USE_QR_CODE_OUT属性
 * @note 设备可生成QR Code 是在bit7中进行配置 0为不可生成QR Code 1为可生成QR Code
 */
void gwin_set_m_config_io_oob_qr_code_out(uint8_t enable_qr_code_out)
{
    m_config.io = (m_config.io & 0x7F) | (enable_qr_code_out ? 0x80 : 0x00);

    GWIN_DEBUG("m_config.io = %X\r\n", m_config.io);
}

// 保证主任务优先级最高！！！保证低优先级任务调用！！！否则 gwin_main_cfg_get 会有问题！！！
/**
 * @brief 获取时区
 */
int8_t gwin_get_timezone(void)
{
    int8_t value = 0;
    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_TIME_ZONE, (uint32_t)&value);

    GWIN_DEBUG("%d", value);

    return (int8_t)(value);
}

/**
 * @brief 获取utc
 */
uint32_t gwin_get_utc_time(void)
{
    uint32_t value = 0;
    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_UTC_TIME, (uint32_t)&value);

    GWIN_DEBUG("%d", value);

    return (uint32_t)(value);
}

/**
 * @brief 获取天气
 */
uint16_t gwin_get_weather(void)
{
    uint32_t value = 0;
    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_WEATHER, (uint32_t)&value);

    GWIN_DEBUG("%d", value);

    return (uint16_t)(value);
}

/**
 * @brief 获取获取系统状态
 */
uint8_t gwin_get_system_state(void)
{
    uint32_t value = 0;
    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_SYS_STATE, (uint32_t)&value);

    GWIN_DEBUG("%d", value);

    return (uint8_t)(value);
}

/**
 * @brief 获取配网超时时间
 */
uint32_t gwin_get_network_timeout(void)
{
    uint32_t value = 0;
    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK_TIMEOUT, (uint32_t)&value);

    GWIN_DEBUG("%d", value);

    return (uint8_t)(value);
}

/**
 * @brief 获取model pid
 */
void gwin_get_model_pid(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_MODEL_PID, value);
}

/**
 * @brief 获取mac
 */
void gwin_get_mac_addr(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_MAC_ADDR, value);
}

/**
 * @brief 获取spec
 */
void gwin_get_spec(uint32_t value)
{
    GWIN_DEBUG("0x%x", value);

    gwin_main_cfg_get(MAIN_TASK_MSG_CFG_SUBTYPE_SPEC, value);
}


/*-------------------------- END OF FILE ------------------------------------*/

